import React from 'react'
// ===================================================================== Temp
import SubmitForm from '#cpt/temp/SubmitForm'
// ===================================================================== 
const { $Lazy } = window
// ===================================================================== Lazy
const Modal 	= $Lazy.state(()=>import('@antd/modal'))
const confirm 	= $Lazy.file(()=>import('@antd/confirm'))
// ===================================================================== 
const Index = function( props ){
	const { title = '', content, suffix, prefix, width=650, minWidth, labelWidth='s6', api, param, clear, scroll, refresh=true, 
		onRefresh, onClear, onSubmit, isConfirm, submit, getSubmit, bodyStyle, modal, onForm, enter=true
	} = props
	return (
		<Modal
			width 		= { width }
			onRef		= { ref => this.modal = ref }
			title		= { title }
			loading 	= { this.state.submitLoading }
			isFullScroll = { scroll }
			close 		= { ()=> this.formRef?.reset?.() }
			bodyClassName = 'some'
			minWidth	= { minWidth }
			onOk 		= { () => {
				const bool = typeof isConfirm === 'function' ? isConfirm() : isConfirm
				if(bool){
					confirm.then(f=>{
						f({
							msg:`是否确认${title}?`,
							onOk: close => {
								this.formRef.submit()
								close()
							}
						})
					})
				}
			}}
			enter = { enter }
			{...props}
			bodyStyle 	= { bodyStyle }
		>
			{ prefix }
			{
				content ? content : SubmitForm.call(this,{ api, param, clear, refresh, labelWidth, msg:title, onRefresh, onClear, getSubmit, modal, onForm,
					onSubmit: onSubmit ? param => onSubmit(param, this.modal.close) : null, 
					...submit
				 })
			}
			{ suffix }
		</Modal>
	)
}
export default Index